Beaker = Button.extend({
	ctor:function(parent, zIndex, tag, callback, back){
		this._super(parent, zIndex, tag, "#beaker.png", callback, back);
		this.initBeaker();
	},
	initBeaker:function(){
		// 水位线
		var line = new cc.Sprite("#beaker_line.png");
		line.setOpacity(0);
		line.setScale(1, 0.5);
		line.setPosition(this.width * 0.5, line.height * 0.5 + 5);
		this.addChild(line, 5, TAG_BEAKER_LINE);

		// 沉淀
		var deposit = new cc.Sprite("#deposit.png");
		deposit.setPosition(this.width * 0.5, 18);
		deposit.setOpacity(0);
		this.addChild(deposit,8,TAG_BEAKER_DEPOSIT);
		// 盐
		var salt = new cc.Sprite("#salt5.png");
		salt.setPosition(this.width * 0.5, 38);
		salt.setScale(0.7);
		salt.setOpacity(0);
		this.addChild(salt,8,TAG_BEAKER_SALT);
		// 苯甲酸结晶晶体
		var jingti = new cc.Sprite("#salt5.png");
		jingti.setPosition(this.width * 0.5+2, 10);
		jingti.setScale(0.7,0.3);
		jingti.setOpacity(0);
		this.addChild(jingti,8,TAG_BEAKER_JINGTI);
		// 活性炭
		var tan = new cc.Sprite("#tan.png");
		tan.setPosition(this.width * 0.5+2, 38);
		tan.setScale(0.7);
		tan.setOpacity(0);
		this.addChild(tan,8,TAG_BEAKER_TAN);
		
		// 搅拌
		var deposit1 = new cc.Sprite("#deposit1.png");
		deposit1.setPosition(31, 19);
		deposit1.setScale(2.3,1);
		deposit1.setOpacity(0);
		this.addChild(deposit1,8,TAG_BEAKER_DEPOSIT1);

		this.callNext = cc.callFunc(function(){
			gg.flow.next();
		}, this);
		this.callNext.retain();
		this.loadName();
	},
	loadName:function(){
		var name = "";
		switch (this.getTag()) {
		case TAG_BEAKER:
			name = "①";
			break;
		case TAG_BEAKER2:
			name = "②";
			break;
		case TAG_BEAKER3:
			name = "③";
				break;
		}
		var nameLabel = new cc.LabelTTF(name, gg.fontName, 20);
		nameLabel.setColor(cc.color(0,0,0));
		nameLabel.setPosition(this.width * 0.5, 60);
		this.addChild(nameLabel);
		this.setCascadeOpacityEnabled(true);
	},
	showSalt:function(next){
		var salt = this.getChildByTag(TAG_BEAKER_SALT);
		var seq = null;
		if(next){
			seq = cc.sequence(cc.fadeIn(0),cc.moveTo(1, cc.p(30,18)),this.callNext);
		} else {
			seq = cc.sequence(cc.fadeTo(0.5,255));
		}
		salt.runAction(seq);
	},
	showJingti:function(next){
		var jing = this.getChildByTag(TAG_BEAKER_JINGTI);
		var seq = null;
		seq = cc.sequence(cc.fadeTo(3.5,255));		
		jing.runAction(seq);
	},
	showTan:function(next){
		var tan = this.getChildByTag(TAG_BEAKER_TAN);
		var seq = null;
		if(next){
			seq = cc.sequence(cc.fadeIn(0),cc.moveTo(1, cc.p(32,14)),this.callNext);
		} else {
			seq = cc.sequence(cc.fadeTo(0.5,255));
		}
		tan.runAction(seq);
	},
	showDep:function(next){
		var deposit = this.getChildByTag(TAG_BEAKER_DEPOSIT);
		var seq = null;
		if(next){
			seq = cc.sequence(cc.fadeTo(0.5,255),this.callNext);
		} else {
			seq = cc.sequence(cc.fadeTo(0.5,255));
		}
		deposit.runAction(seq);
	},
	upLine:function(next){
		var line = this.getChildByTag(TAG_BEAKER_LINE);
		var show = cc.fadeTo(0.5,255);
		// 水位线上升
		var move = cc.moveBy(1.5,cc.p(0,this.height * 0.3));
		var seq = null;
		if(next){
			seq = cc.sequence(show, move, this.callNext);
		} else {
			seq = cc.sequence(show, move);
		}
		line.runAction(seq);
	},
	downLine:function(){
		var line = this.getChildByTag(TAG_BEAKER_LINE);
		if(line.getOpacity() == 0){
			line.setOpacity(255);
			line.setPosition(this.width * 0.5, line.height * 0.5 + this.height * 0.3 + 5);	
		}
		// 水位线下降
		var rotate = cc.rotateTo(0.8, 50);
		var move = cc.moveTo(0.8,cc.p(30,44));
		var scale = cc.scaleTo(0.8,1.35);
		var spawn = cc.spawn(rotate, move, scale);
		var seq = cc.sequence(spawn,cc.callFunc(function(){
			var move = cc.moveBy(1.5,cc.p(-16, -32));
			var scale = cc.scaleTo(1.5,0.5);
			var rot=cc.rotateTo(0.5, 45);
			var spawn = cc.spawn(move, scale,rot);
			var fade = cc.fadeTo(0.5,0);
			var seq = cc.sequence(spawn,fade);
			line.runAction(seq);
		}, this));
		line.runAction(seq);
	},
	downLine2:function(){
		var line = this.getChildByTag(TAG_BEAKER_LINE);
		if(line.getOpacity() == 0){
			line.setOpacity(255);
			line.setPosition(this.width * 0.5, line.height * 0.5 + this.height * 0.3 + 5);	
		}
		var rotate = cc.rotateTo(0.8, -50);
		var move = cc.moveTo(0.8,cc.p(30,38));
		var scale = cc.scaleTo(0.8,1.35);
		var spawn = cc.spawn(rotate, move, scale);
		var seq = cc.sequence(spawn,cc.callFunc(function(){
			var move = cc.moveBy(1.5,cc.p(20, -20));
			var scale = cc.scaleTo(1.5,0.5);
			var spawn = cc.spawn(move, scale);			
			var fade = cc.fadeTo(0.5,0);
			var sca=cc.scaleTo(0.1, 1);
			var rot=cc.rotateTo(0.1, 0);
			var mov=cc.moveTo(0.1, cc.p(30,10));
			var spa=cc.spawn(sca,rot,mov);
			var seq = cc.sequence(spawn,fade,spa);
			line.runAction(seq);
		}, this));
		line.runAction(seq);
	},
	waitDiss:function(next){
		// 等待溶解
		var salt = this.getChildByTag(TAG_BEAKER_SALT);
		var deposit1=this.getChildByTag(TAG_BEAKER_DEPOSIT1);
		var seq = null;
		if(next){
			seq = cc.sequence(cc.delayTime(1),cc.callFunc(function() {
				deposit1.runAction(cc.sequence(cc.fadeIn(0.5),cc.delayTime(2),cc.fadeOut(2)));
			}, this),cc.fadeOut(0.5));
		} else {
			seq = cc.sequence(cc.delayTime(2),cc.fadeTo(1.5,0));
		}
		salt.runAction(seq);
	},
	waitTan:function(next){
		// 搅拌扩散
		var tan = this.getChildByTag(TAG_BEAKER_TAN);
		var deposit1=this.getChildByTag(TAG_BEAKER_DEPOSIT1);
		var seq = null;
		if(next){
			seq = cc.sequence(cc.delayTime(1),cc.callFunc(function() {
				deposit1.runAction(cc.sequence(cc.fadeIn(0),cc.tintTo(0, 105, 105, 105),cc.delayTime(2)));
			}, this),cc.fadeOut(0.5));
		} else {
			seq = cc.sequence(cc.delayTime(2),cc.fadeTo(1.5,0));
		}
		tan.runAction(seq);
	},
	waitTan2:function(){
		// 等待溶解
		var tan = this.getChildByTag(TAG_BEAKER_TAN);
		var seq = null;
		seq = cc.sequence(cc.delayTime(1),cc.fadeTo(0.8,0));
		tan.runAction(seq);
	},
	waitJing:function(){
		// 等待溶解
		var salt = this.getChildByTag(TAG_BEAKER_JINGTI);
		var seq = null;		
		seq = cc.sequence(cc.delayTime(1.2),cc.fadeTo(0.8,0));
		salt.runAction(seq);
	},
	hide:function(delay,next){
		var seq = null;
		if(delay != null && next != null){
			seq = cc.sequence(cc.delayTime(delay),this.callNext);
		} else if(delay != null){
			seq = cc.sequence(cc.delayTime(delay));
		} else {
			seq = cc.sequence(cc.fadeTo(0.5,0));
		}
		this.setCascadeOpacityEnabled(true);
		this.runAction(seq);
	},
	dead:function(){

	},
	onExit:function(){
		this.callNext.release();
	}
});